package com.hbnu.service.impl;

import com.hbnu.mapper.UserMapper;
import com.hbnu.pojo.Request;
import com.hbnu.pojo.User;
import com.hbnu.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public User login(Request rq) {
        return userMapper.getUserByUidAndPassword(rq.getUid(), rq.getPassword());
    }

    @Override
    public void register(Request rq) {
        userMapper.insertUser(rq.getUid(), rq.getPassword(), rq.getUname());
    }

    @Override
    public int updateUserPassword(Request rq) {
        return userMapper.updateUserPassword(rq.getUid(), rq.getOldpwd(), rq.getNewpwd());
    }

    @Override
    public void updateUserAddress(Request rq) {
        userMapper.updateUserAddressByUid(rq.getUid(), rq.getAddress());
    }

    @Override
    public void updateUserTelephone(Request rq) {
        userMapper.updateUserTelephoneByUid(rq.getUid(), rq.getTelephone());
    }

    @Override
    public void updateUserUname(Request rq) {
        userMapper.updateUserUnameByUid(rq.getUid(), rq.getUname());
    }


}
